<template>
	<div class="wrapper">
		<swiper ref="mySwiper" :options="swiperOptions" v-if="showSwiper">  <!-- 开始传入的list是空数组，v-if=falst,则轮播图最开始就显示第一张啦！ -->
			<!-- slides -->
		    <swiper-slide v-for="item of list" :key="item.id">
		    	<img class="swiper-img" :src="item.imgUrl">
		    </swiper-slide>

		    <!-- Optional controls -->
		    <div class="swiper-pagination" slot="pagination"></div>   <!-- slot插槽的形式上传数据 -->
		</swiper>
	</div>
</template>

<script>
export default{
	name: 'HomeSwiper',
	props: {
		list: Array
	},
	data: function() {
		return {
			swiperOptions: {
	          	pagination: '.swiper-pagination',
	          	loop: true //可以左右切换
        	},
        	// swiperList: [{
         //  		id: '0001',
         //  		imgUrl: 'http://img1.qunarzz.com/sight/source/1811/6d/5afbf529076ef6.jpg_r_640x214_7414b151.jpg'
         //  	},{
         //  		id: '0002',
         //  		imgUrl: 'http://img1.qunarzz.com/sight/source/1811/8c/80108ae993d1e3.jpg_r_640x214_89628567.jpg'
         //  	},{
         //  		id: '0003',
         //  		imgUrl: 'http://img1.qunarzz.com/sight/source/1509/7e/e23304b4b90d16.jpg_r_640x214_87d3b4f1.jpg'
         //  	}]
		}
	},
	computed: {
		showSwiper: function() {
			return this.list.length
		}
	}
}
</script>
<style lang="stylus" scoped>
	//分页点样式进行一个穿透,当前选中的点点的设置
	.wrapper >>> .swiper-pagination-bullet-active{
			background: #fff !important;
		}
	.wrapper{
		overflow: hidden;
		width:100%;
		height:0;
		padding-bottom:31.25%; //轮播图的宽高比,117.19/375=0.312506
		.swiper-img{
			width:100%;
		}
	}
</style>